package com.hurt.competition.player.controller;

import com.hurt.competition.common.util.CoreResultBuilder;
import com.hurt.competition.common.vo.CoreResult;
import com.hurt.competition.player.dto.ScoreDataDto;
import com.hurt.competition.player.dto.ScoreDataRes;
import com.hurt.competition.player.service.CompetitionPlayerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/data")
public class DataController {

    @Autowired
    private CompetitionPlayerService competitionPlayerService;

    @GetMapping("score")
    public CoreResult score(Integer competitionId){
        // 统计每个比赛的参赛选手的分数段段人数
        ScoreDataDto scoreDataDto = competitionPlayerService.queryData(competitionId);

        // 封装数据
        ScoreDataRes res = new ScoreDataRes();
        List<String> columns = new ArrayList<>();
        columns.add("不及格");
        columns.add("60-70分");
        columns.add("70-80分");
        columns.add("80-90分");
        columns.add("90-100分");
        res.setScoreList(columns);

        List<Integer> nums = new ArrayList<>();
        nums.add(scoreDataDto.getFailCount());
        nums.add(scoreDataDto.getCount67());
        nums.add(scoreDataDto.getCount78());
        nums.add(scoreDataDto.getCount89());
        nums.add(scoreDataDto.getCount910());
        res.setNums(nums);

        return CoreResultBuilder.success(res);
    }
}
